package com.yanqu.road.logic.activity.foxcard.game.effect;

import com.yanqu.road.entity.activity.foxcard.FoxCardPack;
import com.yanqu.road.entity.activity.foxcard.FoxHandCard;
import com.yanqu.road.entity.activity.foxcard.FoxSaleCard;
import com.yanqu.road.entity.activity.foxcard.config.FoxCardMagicWeaponConfig;
import com.yanqu.road.entity.activity.foxcard.config.FoxCardShopConfig;
import com.yanqu.road.entity.activity.foxcard.config.FoxCardSorceryConfig;
import com.yanqu.road.entity.activity.foxcard.config.FoxCardSpellConfig;
import com.yanqu.road.logic.activity.foxcard.FoxCardConfig;
import com.yanqu.road.logic.activity.foxcard.game.FoxCardGameLogic;
import com.yanqu.road.logic.activity.foxcard.game.eFoxCardTriggerType;
import com.yanqu.road.logic.activity.foxcard.game.eFoxCardType;

/**
 * 商店中对应类型的商品免费购买
 * cardtepy|0|0|0|0|0
 */
public class FoxCardEffect37 extends FoxCardEffectBase {
    @Override
    protected void effectHandle(FoxCardGameLogic gameLogic, FoxHandCard handCard) {
        FoxCardConfig config = gameLogic.getConfig();
        if (triggerType == eFoxCardTriggerType.SHOP_INIT || (triggerType == eFoxCardTriggerType.ADD && handCard == null && gameLogic.getGameData().getIsShopping())) {
            //进入商店时和获得卡牌时,把对应类型的商品价格设置为0
            int cardType = Integer.valueOf(effectConfig.getParamsList().get(0));
            for (FoxSaleCard saleCard : gameLogic.getGameData().getShop().getSaleCards()) {
                if (saleCard.getType() == cardType) {
                    saleCard.setPrice(0);
                }
            }

            for (FoxCardPack cardPack : gameLogic.getGameData().getShop().getCardPacks()) {
                if (cardPack.getPackType() == cardType) {
                    cardPack.setPrice(0);
                }
            }
        } else if (triggerType == eFoxCardTriggerType.REFRESH_SHOP) {
            //刷新商品时,把对应类型的商品价格设置为0
            //进入商店时,把对应类型的商品价格设置为0
            int cardType = Integer.valueOf(effectConfig.getParamsList().get(0));
            for (FoxSaleCard saleCard : gameLogic.getGameData().getShop().getSaleCards()) {
                if (saleCard.getType() == cardType) {
                    saleCard.setPrice(0);
                }
            }
        } else if (triggerType == eFoxCardTriggerType.REMOVE) {
            //自身销毁时,价格恢复
            int cardType = Integer.valueOf(effectConfig.getParamsList().get(0));
            for (FoxSaleCard saleCard : gameLogic.getGameData().getShop().getSaleCards()) {
                if (saleCard.getType() == cardType) {
                    if (cardType == eFoxCardType.EFFECT.getValue()) {
                        int price = config.calcEffectCardPrice(config.getEffectCardConfigMap().get(saleCard.getConfigId()), saleCard.getVersionEffect());
                        saleCard.setPrice(price);
                    } else if (cardType == eFoxCardType.HAND.getValue()) {
                        int price = config.calcHandCardPrice(saleCard.getReinforceEffect(), saleCard.getVersionEffect(), saleCard.getSealEffect());
                        saleCard.setPrice(price);
                    } else if (cardType == eFoxCardType.MAGIC_WEAPON.getValue()) {
                        FoxCardMagicWeaponConfig weaponConfig = config.getMagicWeaponConfigMap().get(saleCard.getConfigId());
                        if (weaponConfig != null) {
                            saleCard.setPrice(weaponConfig.getGold());
                        }
                    } else if (cardType == eFoxCardType.SPELL.getValue()) {
                        FoxCardSpellConfig spellConfig = config.getSpellConfigMap().get(saleCard.getConfigId());
                        if (spellConfig != null) {
                            saleCard.setPrice(spellConfig.getGold());
                        }
                    } else if (cardType == eFoxCardType.SORCERY.getValue()) {
                        FoxCardSorceryConfig sorceryConfig = config.getSorceryConfigMap().get(saleCard.getConfigId());
                        if (sorceryConfig != null) {
                            saleCard.setPrice(sorceryConfig.getGold());
                        }
                    }
                }
            }

            for (FoxCardPack cardPack : gameLogic.getGameData().getShop().getCardPacks()) {
                if (cardPack.getPackType() == cardType) {
                    FoxCardShopConfig shopConfig = config.getShopConfigMap().get(cardPack.getCardPackId());
                    if (shopConfig != null) {
                        cardPack.setPrice(shopConfig.getGold());
                    }
                }
            }
        }
    }
}
